//
//  File.swift
//  
//
//  Created by CSS on 8/17/23.
//

import Foundation

public enum LanguageType: Int, CaseIterable {
    
    case french, german, italian, japanese, portuguese, russian, chinese, spanish, turkish
    case thai, korean, csech, dutch, indonesian, polish, traditionalChinese, hindi, malay, arabic
    case catalan, danish, hebrew, hungarian, romanian, slovak, swedish, vietnamese
    
    var languageName: String {
        switch self {
        case .french:
            return "法语"
        case .german:
            return "德语"
        case .italian:
            return "意大利语"
        case .japanese:
            return "日语"
        case .portuguese:
            return "葡萄牙语"
        case .russian:
            return "俄语"
        case .chinese:
            return "中文"
        case .spanish:
            return "西班牙语"
        case .turkish:
            return "土耳其语"
        case .thai:
            return "泰语"
        case .korean:
            return "韩语"
        case .csech:
            return "捷克语"
        case .dutch:
            return "荷兰语"
        case .indonesian:
            return "印尼语"
        case .polish:
             return "波兰语"
        case .traditionalChinese:
            return "繁体中文"
        case .hindi:
            return "印地语"
        case .malay:
            return "马来语"
        case .arabic:
            return "阿拉伯语"
        case .catalan:
            return "加泰罗尼亚语"
        case .danish:
            return "丹麦语"
        case .hebrew:
            return "希伯来语"
        case .hungarian:
            return "匈牙利语"
        case .romanian:
            return "罗马尼西亚语"
        case .slovak:
            return "斯洛伐克语"
        case .swedish:
            return "瑞典语"
        case .vietnamese:
            return "越南语"
        }
    }
    
    var languageId: String {
        switch self {
        case .french:
            return "fr"
        case .german:
            return "de"
        case .italian:
            return "it"
        case .japanese:
            return "ja"
        case .portuguese:
            return "pt-PT"
        case .russian:
            return "ru"
        case .chinese:
            return "zh-Hans"
        case .spanish:
            return "es"
        case .turkish:
            return "tr"
        case .thai:
            return "th"
        case .korean:
            return "ko"
        case .csech:
            return "cs"
        case .dutch:
            return "nl"
        case .indonesian:
            return "id-ID"
        case .polish:
            return "pl"
        case .traditionalChinese:
            return "zh-Hant"
        case .hindi:
            return "hi"
        case .malay:
            return "ms"
        case .arabic:
            return "ar"
        case .catalan:
            return "ca"
        case .danish:
            return "da"
        case .hebrew:
            return "he"
        case .hungarian:
            return "hu"
        case .romanian:
            return "ro"
        case .slovak:
            return "sk"
        case .swedish:
            return "sv"
        case .vietnamese:
            return "vi"
        }
    }
    
    var languageBundle: Bundle {
        let mainBundle = Bundle.main
        if let bundlePath = mainBundle.path(forResource: languageId, ofType: "lproj"), let stringBundle = Bundle(path: bundlePath) {
            return stringBundle
        }
        return mainBundle
    }
    
    func languageBundle(inBundle bundle: Bundle = .main) -> Bundle {
        if let bundlePath = bundle.path(forResource: languageId, ofType: "lproj"), let stringBundle = Bundle(path: bundlePath) {
            return stringBundle
        }
        return bundle
    }
    
    static func languageType(withIndex index: Int) -> LanguageType {
        .init(rawValue: index) ?? .french
    }
    
}
